<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ConstructionDiary extends Model
{
    use HasFactory;

    protected $fillable = [
        'project_id','user_id','date','day_weather','day_temperature','day_wind','night_weather','night_temperature','night_wind','work_content','progress','quality_safety','materials','equipment','problems','solutions','next_day_plan','day_remarks','night_remarks','remarks','files'
    ];

    const POSTONLY = [
        'project_id','user_id','date','day_weather','day_temperature','day_wind','night_weather','night_temperature','night_wind','work_content','progress','quality_safety','materials','equipment','problems','solutions','next_day_plan','day_remarks','night_remarks','remarks','files'
    ];


    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function application()
    {
        return $this->hasOne(Application::class,'source_id','id')->where('model','Diary')->orderBy('id','desc');
    }

    public function project()
    {
        return $this->hasOne(Project::class,'id','project_id')->select('id','title','status');
    }

}
